var someValue = 'this is a string';
// 强制转换
var strLength = someValue.length;
var strLength1 = someValue.length;
console.log(strLength);
console.log(strLength1);
// 非空断言 : 参数 可以是字符串 undefined null
function myFunc(maybeString) {
    var onlyString = maybeString;
    var ignoreUndefinedAndNull = maybeString;
    console.log(onlyString, ignoreUndefinedAndNull);
}
// tsconfig.json
myFunc(undefined);
myFunc('hello');
function printEAngA(emp) {
    console.log(emp.name);
    // in
    if ('privileges' in emp) {
        console.log('privileges', emp.privileges);
    }
    if ('startDate' in emp) {
        console.log('startDate', emp.startDate);
    }
}
printEAngA({ name: '小三', startDate: new Date() });
// 联合类型
// 交叉类型
var CarTransmission;
(function (CarTransmission) {
    CarTransmission[CarTransmission["Automatic"] = 200] = "Automatic";
    CarTransmission[CarTransmission["Manual"] = 300] = "Manual";
})(CarTransmission || (CarTransmission = {}));
var ENVAL = Math.PI;
function envalPrice(vehicle) {
    switch (vehicle.vType) {
        case 'motor':
            return vehicle.make * ENVAL;
        case 'car':
            return vehicle.transmission * ENVAL;
        case 'truck':
            return vehicle.capacity * ENVAL;
        default:
    }
}
var ve = {
    // vType:'truck',
    // capacity: 1000
    vType: 'car',
    transmission: CarTransmission.Manual
};
console.log(envalPrice(ve));
// 题 :
// 宠物 动物 共同的属性 :
// name age
// 猫 : 加菲猫 猪肉卷  无毛猫 : 线团 蓝猫 : 白兔
// 狗 : 柯基 : 香香的 金毛:臭臭的 斗牛 : 黄黄的 萨摩耶: 傻傻的
// 遛弯 : 函数  (animal:联合类型)
// 判断 带的是哪个动物  根据带的动物选择食物
var CatType;
(function (CatType) {
    CatType["GARFIELD"] = "\u732A\u8089\u5377";
    CatType["HAIRLESSCAT"] = "\u7EBF\u56E2";
    CatType["BLUECAT"] = "\u767D\u5154";
})(CatType || (CatType = {}));
var DogType;
(function (DogType) {
    DogType["KIRKY"] = "\u9999\u9999\u7684";
    DogType["GOLDEN"] = "\u81ED\u81ED\u7684";
    DogType["Bulldog"] = "\u9EC4\u9EC4\u7684";
    DogType["SAMOYE"] = "\u50BB\u50BB\u7684";
})(DogType || (DogType = {}));
function takeWalk(pet) {
    var myPet = '';
    var food;
    if ('typeDog' in pet) {
        switch (pet.typeDog) {
            case DogType.KIRKY:
                myPet = '柯基';
                food = DogType.KIRKY;
                break;
            case DogType.GOLDEN:
                myPet = '金毛';
                food = DogType.GOLDEN;
                break;
            case DogType.Bulldog:
                myPet = '斗牛';
                food = DogType.Bulldog;
                break;
            case DogType.SAMOYE:
                myPet = '萨摩耶';
                food = DogType.SAMOYE;
                break;
        }
    }
    if ('typeCat' in pet) {
        switch (pet.typeCat) {
            case CatType.GARFIELD:
                myPet = '加菲猫';
                food = CatType.GARFIELD;
                break;
            case CatType.HAIRLESSCAT:
                myPet = '无毛猫';
                food = CatType.HAIRLESSCAT;
                break;
            case CatType.BLUECAT:
                myPet = '蓝猫';
                food = CatType.BLUECAT;
                break;
        }
    }
    return "\u4ECA\u5929\u8981\u5E26" + myPet + "\u5BA0\u7269\u5E26\u7740" + food + "\u53BB\u905B\u5F2F";
}
var pet = {
    name: '蓝猫',
    age: 3,
    typeCat: CatType.BLUECAT,
    likeCatFood: CatType.BLUECAT
};
console.log(takeWalk(pet));
// 设计一个函数 参数是回调 回调的参数必须是string 回调的返回值是string
// 该函数返回值是字符串数组
// 声明函数类型
// 泛型  规范
// type FN_TYPE = <T>(str:T)=>T
//
//
// let call = (callback: FN_TYPE): string[] => {
//   return ['1']
// };
//
// call(<T>(str: T): T=> {
//   return ;
// });
// 泛型 : 不是只定义变量 得到一个规范类型
function identity(value, message) {
    console.log(message);
    return value;
}
var code = identity({ name: '小李', age: 20 }, '上山打老鼠');
var a = {
    arg: '123'
};
// 泛型类
var Gen = /** @class */ (function () {
    function Gen() {
    }
    return Gen;
}());
var gen = new Gen();
gen.zeroValue = 123;
gen.add = function (x, y) {
    return x + y > 3;
};
var sem = { name: 'sm', age: 13 };
console.log(typeof sem);
var k1 = 'toString';
var k3 = 123;
var aa = { a: { name: '123', age: 12 } };
